<%@ page contentType="text/html;charset=UTF-8" language="java"  import="java.util.*" trimDirectiveWhitespaces="true" %>
<%@include file="/WEB-INF/pages/common/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>贵金属参数</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%@include file="/WEB-INF/pages/common/commonCss.jsp"%>
    <link rel="stylesheet" href="${basePath}/resources/css/colorpicker.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/datepicker.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/uniform.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/select2.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/matrix-style.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/matrix-media.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/bootstrap-wysihtml5.css" />


</head>
<style>
    .select2-container {
        float:left;
        width: 35%;
    }
    em,strong{ color:#C00;}
    span.error{color:#C00; padding:0 6px;}

</style>
<body>

<!--Header-part-->
<%@include file="/WEB-INF/pages/common/head.jsp"%>


<!--sidebar-menu-->
<%@include file="/WEB-INF/pages/common/left.jsp"%>

<div id="content">
    <div id="content-header">
        <div id="breadcrumb"> <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> </a>
            <a href="#" class="current">贵金属估价参数编辑</a> </div>
        <%--<h1>平台商品新增</h1>--%>
    </div>

    <div class="container-fluid">


        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
                        <h5></h5>
                    </div>
                    <div class="widget-content nopadding">
                        <form  id="form" method="POST" class="form-horizontal" >
                            <input type="hidden" name="id" value="${metalcalculation.id}">
                            <div class="control-group" >
                                <label class="control-label">类型:${metalcalculation.type}</label>
                                <div class="controls">
                                    <select  name="type"   onchange="metalcalculation.change(this)"  >
                                        <c:forEach items="${metals}" var="metal">
                                            <option value="${metal.codevalue}"  ${metalcalculation.type==metal.codevalue?'selected':''} >${metal.dictname}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label">系列 :</label>
                                <div class="controls">
                                    <input type="hidden" id="beforeSeries" value="${metalcalculation.series}">
                                    <select  name="series" id="series" >
                                    </select>
                                </div>
                            </div>

                            <%@include file="filed.jsp" %>

                            <div class="control-group">
                                <div class="controls">
                                    <button  type="submit" class="btn btn-success">保存</button>
                                    <button type="reset" class="btn btn-default" onclick="history.go(-1)">返回</button>
                                </div>
                            </div>

                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


<!-- Modal -->

</div>



<!--Footer-part-->
<%@include file="/WEB-INF/pages/common/footer.jsp"%>

<!--end-Footer-part-->

<%@include file="/WEB-INF/pages/common/commonJS.jsp"%>
<%--<script src="${basePath}/resources/js/bootstrap.min.js"></script>--%>
<script src="${basePath}/resources/js/jquery.validate.js"></script>
<script src="${basePath}/resources/js/admin/validate.js"></script>


<script>
    $(function(){
        metalcalculation.getSeries('${metalcalculation.type}');

        //jquery.validate
        $("#form").validate({
            submitHandler: function() {
                //验证通过后 的js代码写在这里
                var $form = $(form);
                var data = $form.serialize();
                console.log(JSON.stringify(data));
                //$("#jsForm").submit();
                $.ajax({
                    url:adminPath +'/service/metalcalculation/update',
                    type:'POST',
                    data:data,
                    success:function (data) {
                        console.log('data==='+data);
                        if(data == 1){
                            window.location.href =  adminPath +"/service/metalcalculation/list";
                        }
                    }
                });

            }
        })

    })

    var metalcalculation = {
        change:function (obj) {
            var $this = $(obj);
            var codevalue =  $this.val();
            metalcalculation.getSeries(codevalue);
        },
        getSeries:function (codevalue) {
            var beforeValue = $("#beforeSeries").val();
            $.ajax({
                url:adminPath+"/service/metalcalculation/listSeriesByMetalCode",
                type:"post",
                data:{codevalue:codevalue},
                success:function (data) {
                    var html= "";
                    if(data && data.length>0){
                        for(var i=0,len=data.length;i<len;i++){
                            var defaultValue = '';
                            if(data[i].codevalue == beforeValue){
                                defaultValue = 'selected';
                            }
                            html +=  " <option value='"+data[i].codevalue+"' "+defaultValue+">"+data[i].dictname+"</option>";
                        }
                        $("#series").html(html);
                    }
                }
            });
        }
    };

</script>

</body>
</html>
